package com.yunxin.customui.util;

import com.yunxin.tools.commonbean.DataBean;
import com.yunxin.tools.plantbusiness.ConfigbusinessUtil;
import lombok.Data;

import java.util.*;

public class PageUtil {

    public static Map<String, List<DataBean>> filterMap(Map<String, List<DataBean>> dataMap, String filter){
        Map<String, List<DataBean>> filterDataMap = new HashMap<>();
        Set<String> strings = dataMap.keySet();
        if (filter != null && !filter.equals("")){
            List<String> list = ConfigbusinessUtil.filterId(filter.split(";"), new ArrayList<>(strings));
            for (String s : list) {
                filterDataMap.put(s,dataMap.get(s));
            }
        }else {
            filterDataMap = dataMap;
        }
        return filterDataMap;
    }



    public static List<MethodParam> analysisMethod(String methodStr){
        String[] methods = methodStr.trim().split(";");
        List<MethodParam> methodParams = new ArrayList<>();
        if (methods.length > 0 && methods[0].trim().length() > 0){
            for (String method : methods) {
               // method = method.replace("\r","").replace("\n","").replace("\t","");
                MethodParam methodParam = new MethodParam();
                int i = method.indexOf("(");
                methodParam.methodName = method.substring(0,i);
                methodParam.params = method.substring(i+1,method.length()-1).split("param:");
                methodParams.add(methodParam);
            }
        }
        return methodParams;
    }


    @Data
    public static class MethodParam{
        String methodName;
        String[] params;
    }

}
